Imports System.Data.SqlClient

Public Class ketnoi
    Private sqlConnection As SqlConnection
    Private sqlCommand As SqlCommand
    Private sqlDataReader As SqlDataReader
    Private sqlDataAdapter As SqlDataAdapter

    Private m_connectionString As String = ""
    Public Property ConnectionString() As String
        Get
            Return m_connectionString
        End Get
        Set(ByVal value As String)
            m_connectionString = value
        End Set
    End Property

    Private m_commandText As String = ""
    Public Property CommandText() As String
        Get
            Return m_commandText
        End Get
        Set(ByVal value As String)
            m_commandText = value
        End Set
    End Property
    Private m_commandType As CommandType
    Public Property CommandType() As CommandType
        Get
            Return m_commandType
        End Get
        Set(ByVal value As CommandType)
            m_commandType = value
        End Set
    End Property

    Private m_parameterCollection As String()
    Public Property ParameterCollection() As String()
        Get
            Return m_parameterCollection
        End Get
        Set(ByVal value As String())
            m_parameterCollection = value
        End Set
    End Property

    Private m_valueCollection As String()
    Public Property ValueCollection() As String()
        Get
            Return m_valueCollection
        End Get
        Set(ByVal value As String())
            m_valueCollection = value
        End Set
    End Property

    Private m_returnValueParameter As Integer = -1
    Public Property ReturnValueParameter() As Integer
        Get
            Return m_returnValueParameter
        End Get
        Set(ByVal value As Integer)
            m_returnValueParameter = value
        End Set
    End Property

    Private m_returnValue As Integer = 0
    Public Property ReturnValue() As Integer
        Get
            Return m_returnValue
        End Get
        Set(ByVal value As Integer)
            m_returnValue = value
        End Set
    End Property

    Private m_errorMessage As String = ""
    Public Property ErrorMessage() As String
        Get
            Return m_errorMessage
        End Get
        Set(ByVal value As String)
            m_errorMessage = value
        End Set
    End Property
    Private m_errorCode As Integer = 0
    Public Property ErrorCode() As Integer
        Get
            Return m_errorCode
        End Get
        Set(ByVal value As Integer)
            m_errorCode = value
        End Set
    End Property
    Public Sub New()
        connectionString = "server=(local);" + "database=RecruitVietnamDb;" + "Integrated Security=SSPI;"
    End Sub
    Public Sub New(ByVal conString As String)
        connectionString = conString
        OpenConnection()
    End Sub
    Private Sub OpenConnection()
        If (sqlConnection.ToString = Nothing OrElse sqlConnection.State = ConnectionState.Closed) Then
            sqlConnection = New SqlConnection()
            sqlConnection.ConnectionString = ConnectionString
            sqlConnection.Open()
        End If
    End Sub

    Public Sub CloseConnection()

        If sqlConnection.State = ConnectionState.Open Then
            sqlConnection.Close()
        End If
        sqlConnection.Dispose()
    End Sub
    Private Sub AddParameters(ByVal sqlCommand As SqlCommand)
        Dim i As Integer = 0
        While i < m_parameterCollection.Length
            If m_valueCollection(i) <> "" Then

                sqlCommand.Parameters.AddWithValue(m_parameterCollection(i), m_valueCollection(i))
            End If
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        If m_returnValueParameter <> -1 Then
            sqlCommand.Parameters(m_returnValueParameter).Direction = ParameterDirection.ReturnValue
        End If
    End Sub



End Class
